Deserialize Archetype

Often you may find yourself needing to work with the individual data in code. The following example shows how to deserialize an Archetype from IContent:

  1. using Archetype.Models;
  2. using Newtonsoft.Json;
  3. using Umbraco.Core;
  4. namespace MyNamespace
  5. {
  6. public class MyClass
  7. {
  8. public void MyMethod()
  9. {
  10. var contentService = ApplicationContext.Current.Services.ContentService;
  11. var archetypeValueAsString = contentService.GetById(1234).GetValue<string>("myArchetypeProperty");
  12. var archetype = JsonConvert.DeserializeObject<ArchetypeModel> (archetypeValueAsString);
  13. foreach (var fieldset in archetype)
  14. {
  15. var value = fieldset.GetValue<string>("text");
  16. }
  17. }
  18. }
  19. }